package com.likeycy.my.entity;

import java.util.Objects;

/**
 * @ClassName: Person
 * @Description: Person实体
 * @Author: sodagreen
 * @Date: 2021/2/21 10:09
 * @Version: 1.0
 */
public class Person {

    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 重写equals比较方法
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        if (this.getClass() != obj.getClass()) {
            return false;
        }

        Person person = (Person) obj;
        return this.name.equals(person.name) && this.age == person.age;
    }

    /**
     * 重写equals方法必须重写hashCode方法
     * @return
     */
    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("Person -- finalize()");
    }
}
